package rmi.eventing.types;

import java.text.SimpleDateFormat;

import rmi.eventing.types.AuctionEvent.Type;

public class BidEvent extends Event {
	/**
	 * "BID_PLACED""BID_OVERBID""BID_WON" Events
	 */
	private static final long serialVersionUID = -1758228406970372175L;
	private final String userName;
	private final long auctionID;
	private final double price;
	public BidEvent(String userName, long auctionID, double price){
		super();
		ID = "AC"+idCounter;
		this.userName=userName;
		this.auctionID=auctionID;
		this.price=price;
	}
	public void setType (Type type){
		this.type=type.getValue();
	}
	public enum Type{
		BID_PLACED("BID_PLACED"), BID_OVERBID("BID_OVERBID"),BID_WON("BID_WON");
		
		private String type;
		Type(String type){
			this.type = type;
		}
		public String getValue()
		{      
		      return type ;
		}
	}
	//auction bid
	public double getPrice(){
		return price;
	}
	public String toString(){
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss z");
		String date = dateFormat.format(timestamp);
		if(type.equals("BID_PLACED")){
			return "BID_PLACED: "+date+" - user "+userName+" placed bid "+price+" on auction "+ auctionID;
		}
		else if (type.equals("BID_OVERBID")){
			return "BID_OVERBID: "+date+" -user "+userName+" has been overbid  with "+price+" on auction "+ auctionID;
		}
		else if (type.equals("BID_WON")){
			return "BID_WON: "+date+" -user "+userName+" won with "+price+" on auction "+ auctionID;
		}
		return "BID_EVENT: No type set";
	}
}
